#include "Map.cpp"


void DFSForGraphMap(GraphMap g,int v0) {
    stack<int> s;
    bool visited[g->vexnum+1];
    for (int i = 0; i < g->vexnum+1; ++i) {
        visited[i] = false;
    }
    initStack(s);
    enterStack(s,v0);
    while(!EmptyStack(s)) {
        int v;
        deleteStack(s,&v);
        if (!visited[v]) {
            visit(v);
            visited[v] = true;
            int w = FirstAdjVertex(g,v);
            while (w != -1) {
                if (!visited[w]) {
                    enterStack(s,w);
                }
                w = NextAdjVertex(g,v,w);
            }
        }
    }
}

void DFSForGraph(Graph g,int v0) {
    int v;
    stack<int> s;
    bool visited[g->vexnum+1];
    for (int i = 0; i < g->vexnum+1; ++i) {
        visited[i] = false;
    }
    initStack(s);


    enterStack(s,v0);
    while(!EmptyStack(s)) {
        deleteStack(s,&v);
        if (!visited[v]) {
            visit(v);
            visited[v] = true;
            ArcNode* p = g->vertex[v]->firstArc;
            while (p != NULL) {
                enterStack(s,p->adj);
                p = p->next;
            }
        }
    }
}

int main(void){
    Graph g = CreateGraphByFile("Map.txt");
    DFSForGraph(g,1);
//    GraphMap g2 = CreateGraphMapByFile("Map.txt");
//    DFSForGraphMap(g2,1);
    return 0;
}